import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"

enum Api {
  page = "/infra-service/mpTag/pageMpTag",
  list = "/infra-service/mpTag/listMpTag",
  save = "/infra-service/mpTag/saveMpTag",
  edit = "/infra-service/mpTag/updateMpTag",
  syncMpTag = "/infra-service/mpTag/syncMpTag",
  delete = "/infra-service/mpTag/deleteMpTag",
  deleteBatch = "/infra-service/mpTag/batchDeleteMpTag",
}

/**
 * 列表
 * @param params
 */
export const pageMpTag = (params) => defHttp.get({ url: Api.page, params })

/**
 * 列表
 * @param params
 */
export const listMpTag = (params) => defHttp.get({ url: Api.list, params })

/**
 * 删除
 */
export const deleteMpTag = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}
/**
 * 批量删除
 * @param params
 */
export const batchDeleteMpTag = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdateMpTag = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save
  return defHttp.post({ url: url, params })
}

export const syncMpTag = (params) => {
  return defHttp.post({ url: Api.syncMpTag, params }, { joinParamsToUrl: true })
}
